using System;
using System.Data;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class Code93 : BarcodeCommon, IBarcode
	{
		private DataTable C93_Code = new DataTable("C93_Code");
		public string Encoded_Value
		{
			get
			{
				return this.Encode_Code93();
			}
		}
		public Code93(string input)
		{
			this.Raw_Data = input;
		}
		private string Encode_Code93()
		{
			this.InitCode93();
			string text = this.Add_CheckDigits(this.Raw_Data);
			string text2 = this.C93_Code.Select("Character = '*'")[0]["Encoding"].ToString();
			string text3 = text;
			for (int i = 0; i < text3.Length; i++)
			{
				char c = text3[i];
				try
				{
					text2 += this.C93_Code.Select("Character = '" + c + "'")[0]["Encoding"].ToString();
				}
				catch
				{
					throw new Exception("EC93-1: Invalid data.");
				}
			}
			text2 += this.C93_Code.Select("Character = '*'")[0]["Encoding"].ToString();
			text2 += "1";
			this.C93_Code.Clear();
			return text2;
		}
		private void InitCode93()
		{
			this.C93_Code.Rows.Clear();
			this.C93_Code.Columns.Clear();
			this.C93_Code.Columns.Add("Value");
			this.C93_Code.Columns.Add("Character");
			this.C93_Code.Columns.Add("Encoding");
			this.C93_Code.Rows.Add(new object[]
			{
				"0",
				"0",
				"100010100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"1",
				"1",
				"101001000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"2",
				"2",
				"101000100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"3",
				"3",
				"101000010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"4",
				"4",
				"100101000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"5",
				"5",
				"100100100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"6",
				"6",
				"100100010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"7",
				"7",
				"101010000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"8",
				"8",
				"100010010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"9",
				"9",
				"100001010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"10",
				"A",
				"110101000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"11",
				"B",
				"110100100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"12",
				"C",
				"110100010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"13",
				"D",
				"110010100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"14",
				"E",
				"110010010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"15",
				"F",
				"110001010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"16",
				"G",
				"101101000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"17",
				"H",
				"101100100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"18",
				"I",
				"101100010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"19",
				"J",
				"100110100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"20",
				"K",
				"100011010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"21",
				"L",
				"101011000"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"22",
				"M",
				"101001100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"23",
				"N",
				"101000110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"24",
				"O",
				"100101100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"25",
				"P",
				"100010110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"26",
				"Q",
				"110110100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"27",
				"R",
				"110110010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"28",
				"S",
				"110101100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"29",
				"T",
				"110100110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"30",
				"U",
				"110010110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"31",
				"V",
				"110011010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"32",
				"W",
				"101101100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"33",
				"X",
				"101100110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"34",
				"Y",
				"100110110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"35",
				"Z",
				"100111010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"36",
				"-",
				"100101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"37",
				".",
				"111010100"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"38",
				" ",
				"111010010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"39",
				"$",
				"111001010"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"40",
				"/",
				"101101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"41",
				"+",
				"101110110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"42",
				"%",
				"110101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"43",
				"(",
				"110101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"44",
				")",
				"110101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"45",
				"#",
				"110101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"46",
				"@",
				"110101110"
			});
			this.C93_Code.Rows.Add(new object[]
			{
				"-",
				"*",
				"101011110"
			});
		}
		private string Add_CheckDigits(string input)
		{
			int[] array = new int[input.Length];
			int num = 1;
			for (int i = input.Length - 1; i >= 0; i--)
			{
				if (num > 20)
				{
					num = 1;
				}
				array[i] = num;
				num++;
			}
			int[] array2 = new int[input.Length + 1];
			num = 1;
			for (int i = input.Length; i >= 0; i--)
			{
				if (num > 15)
				{
					num = 1;
				}
				array2[i] = num;
				num++;
			}
			int num2 = 0;
			for (int i = 0; i < input.Length; i++)
			{
				num2 += array[i] * int.Parse(this.C93_Code.Select("Character = '" + input[i] + "'")[0]["Value"].ToString());
			}
			int num3 = num2 % 47;
			input += this.C93_Code.Select("Value = '" + num3 + "'")[0]["Character"].ToString();
			num2 = 0;
			for (int i = 0; i < input.Length; i++)
			{
				num2 += array2[i] * int.Parse(this.C93_Code.Select("Character = '" + input[i] + "'")[0]["Value"].ToString());
			}
			num3 = num2 % 47;
			input += this.C93_Code.Select("Value = '" + num3 + "'")[0]["Character"].ToString();
			return input;
		}
	}
}
